<?xml version="1.0" encoding="UTF-8"?>

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:b="http://www.billib.com/jsf/customtags">

    <ui:composition template="/pages/user/templates/userAdminTemplate.xhtml">
        <ui:define name="pageTitle">
            <h:outputText value="#{msg['user.create.label']}"/>
        </ui:define>    

        <ui:define name="centerPane">
            <a4j:form id="mainForm">
                <h:panelGrid columns="2">
                    <h:outputLabel for="username">
                        <h:outputText value="#{msg['user.username.label']}"/>
                    </h:outputLabel>
                    <a4j:region>
                        <h:panelGroup>
                            <h:inputText id="username" value="#{createUserAction.user.username}" required="true"/>
                            <a4j:commandButton value="#{msg['user.usernameavailability.message']}" action="#{createUserAction.checkUsernameAvailability}" reRender="usernameValidationResult"/>
                            <h:panelGroup id="usernameValidationResult">
                                <h:panelGroup rendered="#{createUserAction.usernameValidationPerformed}">
                                    <h:outputText value="#{msg['user.usernametaken.message']}" rendered="#{!createUserAction.usernameAvailable}"/>
                                    <h:outputText value="#{msg['user.usernameavailable.message']}" rendered="#{createUserAction.usernameAvailable}"/>
                                </h:panelGroup>
                            </h:panelGroup>
                            <h:message for="username"/>
                        </h:panelGroup>
                    </a4j:region>    

                    <h:outputLabel for="password">
                        <h:outputText value="#{msg['user.password.label']}"/>
                    </h:outputLabel>
                    <h:panelGroup>
                        <t:inputSecret id="password" forceId="true" value="#{createUserAction.user.password}" required="true"/>
                        <h:message for="password"/>
                        <b:passwordStrengthMeter passwordFieldId="password"/>
                    </h:panelGroup>

                    <h:outputLabel for="confirmPassword">
                        <h:outputText value="#{msg['user.confirmpassword.label']}"/>
                    </h:outputLabel>
                    <h:panelGroup>
                        <h:inputSecret id="confirmPassword" required="true">
                            <b:confirmValidator compareTo="password"/>
                        </h:inputSecret>
                        <h:message for="confirmPassword"/>
                    </h:panelGroup>

                    <ui:include src="/pages/user/templates/commonUserFields.xhtml">
                        <ui:param name="user" value="#{createUserAction.user}"/>
                    </ui:include>

                </h:panelGrid>

                <h:commandButton value="Create" action="#{createUserAction.createUser}"/>
                <h:commandButton value="Cancel" action="gotoViewUsers" immediate="true"/>
            </a4j:form>
        </ui:define>
    </ui:composition>
</html>
